package MaintMenu.VenPricingUpdTBLN;// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   AddNewPartBL.java

//***************** not fully tested ***************//

import java.sql.*;

// Referenced classes of package win:
//            DnkFunctions

public class VendorMasterCostListing
{
    String sql="";
    String tbl="";
    String pl="";
    String charc="";
    char lastC;
    int totalfiles=1;
    String isCapa="";
    boolean capa;
    String oPL="";
    int pkg=0;
    Double cuft=0.00D;
    String last2Co="";
    String last2C="";
    String orgItem ="";

    String DnkNum="";
    String venNum="";
    String venPLNum="";
    String venPrice="";
    String venQty="";
    float cuFt=0f;
    String vender="";
    String venCapa="";


    String DnkNumF="na";
    String venNumF="na";
    String venPLNumF="na";
    String venPriceF="na";
    String venQtyF="na";
    String cuFtF="na";
    String venderF="na";
    String venCapaF="";

    boolean dupFound;


    public VendorMasterCostListing(String vendor, int filesToUpdate)
    {

        if (vendor=="DP"){
            tbl="_costdepo";


//            DnkNumF="Customer Part #";
//            DnkNumF="["+DnkNumF+"]";
            venNumF="DEPO NO";
            venNumF="["+venNumF+"]";
            venPLNumF="partslink";
            venPLNumF=""+venPLNumF+"";
            venPriceF="unit price";
            venPriceF="["+venPriceF+"]";
            venQtyF="qty ctn";
            venQtyF="'"+venQtyF+"";
//            cuFtF="CU/Ft";
//            cuFtF="["+cuFtF+"]";
//            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";

        }else
        if (vendor=="TW"){
            tbl="_costtygtw";

            DnkNumF="DNK#";
            DnkNumF="["+DnkNumF+"]";
            venNumF="TY#";
            venNumF="["+venNumF+"]";
            venPLNumF="partslink";
//            venPLNumF="'"+venPLNumF+"'";
            venPriceF="PRICE";
//            venPriceF="'"+venPriceF+"'";
            venQtyF="STD QTY";
            venQtyF="["+venQtyF+"]";
            cuFtF="CU/Ft";
            cuFtF="["+cuFtF+"]";
            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";

        }else
        if (vendor=="YCC"){
            tbl="_costYCC";

//            DnkNumF="DNK#";
//            DnkNumF="["+DnkNumF+"]";
            venNumF="ycc";
            venNumF=""+venNumF+"";
            venPLNumF="PARTLINK";
//            venPLNumF="'"+venPLNumF+"'";
            venPriceF="price";
//            venPriceF="'"+venPriceF+"'";
            venQtyF="pcs/ctn";
            venQtyF="["+venQtyF+"]";
            cuFtF="CUFt";
            cuFtF=""+cuFtF+"";
//            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";
        }else
        if (vendor=="GN"){
            tbl="_costgenera";

            DnkNumF="Customer Part #";
            DnkNumF="["+DnkNumF+"]";
            venNumF="item";
            venNumF="["+venNumF+"]";
            venPLNumF="partsLink #";
            venPLNumF="["+venPLNumF+"]";
            venPriceF="net $";
            venPriceF="["+venPriceF+"]";
            venQtyF="STDpk";
            venQtyF="'"+venQtyF+"";
//            cuFtF="CU/Ft";
//            cuFtF="["+cuFtF+"]";
//            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";
        }else
        if (vendor=="TX"){
            tbl="_costtygtx";

            DnkNumF="DNK #";
            DnkNumF="["+DnkNumF+"]";
            venNumF="TYGP #";
            venNumF="["+venNumF+"]";
            venPLNumF="partslink #";
            venPLNumF="["+venPLNumF+"]";
            venPriceF="dnk $";
            venPriceF="["+venPriceF+"]";
//            venQtyF="";
//            venQtyF="''["+venQtyF+"]";
//            cuFtF="CU/Ft";
//            cuFtF="["+cuFtF+"]";
//            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";
        }else
        if (vendor=="AP"){
            tbl="_costap";

//            DnkNumF="DNK#";
//            DnkNumF="["+DnkNumF+"]";
            venNumF="ap";
            venNumF=""+venNumF+"";
            venPLNumF="PRTLNK";
//            venPLNumF="'"+venPLNumF+"'";
            venPriceF="UPX";
//            venPriceF="'"+venPriceF+"'";
            venQtyF="STD P/K";
            venQtyF="["+venQtyF+"]";
            cuFtF="CUFTpER";
            cuFtF=""+cuFtF+"";
//            venderF="vender";
//            venderF="'"+venderF+"'";
            venCapaF="capa";
//            venCapaF="'"+venCapaF+"'";
        }


        while (totalfiles<filesToUpdate+1){



        try
        {
//            DnkFunctions dnk = new DnkFunctions();
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String dataSourceName = "dbLi";
            String dbURL = (new StringBuilder()).append("jdbc:odbc:").append(dataSourceName).toString();
            Connection con = DriverManager.getConnection(dbURL, "", "");
            Statement st = con.createStatement();
            Statement st1 = con.createStatement();
            Statement st2 = con.createStatement();
            Statement st3 = con.createStatement();
            Statement st4 = con.createStatement();
            Statement st5 = con.createStatement();
            Statement st6 = con.createStatement();

            try
            {
                //delete duplicated record if new pricing exists
//                st4.execute("delete * from tblnu;");
                st.execute("select * from ["+tbl+totalfiles+"]");
                System.out.println(totalfiles);
                ResultSet rs = st.getResultSet();
                if(rs != null)
                {
                    sql="delete from "+tbl+" where exists " +
                            "(select "+venNumF+" from ["+tbl+totalfiles+"] where ["+tbl+"]."+venNumF+"=["+tbl+totalfiles+"]."+venNumF+")";
                    System.out.println(sql);
                    st1.execute(sql);

//                    String DESCRIPT;
//                    String MODEL;
//                    String NEW_DES;
//                    String part#
//                    tableB =    "_COSTTYGTW"+filesToUpdate;
//                    onA=        dbInternal;
//                    onB=        dbExternal;
//
////                fieldA1=    "oem_no";       //oem_no  (oem#)
////                fieldB1=    "[OE#]";

//                    String fieldA2=    "[TYG_TW#]";       //DEPOT #



                        while (rs.next()){

                                if (vendor=="TW"){






                                    DnkNum=rs.getString("DNK#");
                                    if (DnkNum==null){
                                        DnkNum="na";
                                    }

                                    if (DnkNum.length()==0){
                                        DnkNum="na";



                                    }

                                    DnkNum="'"+DnkNum+"'";


                                    venNum=rs.getString("TY#");
                                    venNum="'"+venNum+"'";

                                    venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    venPLNum=rs.getString("partslink");
                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";


            //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    venPrice=rs.getString("PRICE");
                                    venPrice="'"+venPrice+"'";

            //                    fieldA4=    "TYG_TW_K";       //Package
                                    venQty=rs.getString("STD QTY");
                                    venQty="'"+venQty+"'";

            //                    fieldA5=    "TYG_TW_C";         //Cu/FT
                                    float cuFt=rs.getLong("CU/Ft");
            //                        cuFt=cuFt;

                                    vender=rs.getString("vender");
                                    vender="'"+vender+"'";

//                                    /* check for dup */
//////                                    String checkitem =checkDup.getString("ty#");
////                                    String sqlf="select * from ["+tbl+totalfiles+"] where [ty#]="+venNum+"";
////                                    System.out.println(sqlf);
////                                    st2.execute(sqlf);
////                                    ResultSet checkDup = st2.getResultSet();
////
////                                    if(checkDup != null)
////                                    {
////
////                                        if (checkDup.next()){
////                                             dupFound=true;
////
////                                            System.out.println("found?"+dupFound);
////                                        }else{
////                                            dupFound=false;
////                                        }
////                                    }
////
////
////
////                                    if (dupFound){
////                                        System.out.println("found");
////
//////                                        if found, then delete
////                                        String sql="select * from "+tbl+" "
//////                                        String sql="delete from "+tbl+" where [ty#]='"+venPLNum+";";
//////                                        st1.execute(sql);
////                                    }else if (!dupFound){
////                                        String sql="INSERT INTO "+tbl+" ([dnk#],capa,[ty#],partslink,[std qty],price,[cu/ft],vender) " +
////                                                "VALUES("+DnkNum+","+venCapa+","+venNum+","+venPLNum+","+venQty+","+venPrice+",'"+cuFt+"',"+vender+")";
////                                    System.out.println(sql);
////                                        st1.execute(sql);
////
////                                    }
//                                    //delete if exisit
//                                    String sql="delete from "+tbl+" where exists " +
//                                            "(select "+venNumF+" from ["+tbl+totalfiles+"] where ["+tbl+"]."+venNumF+"=["+tbl+totalfiles+"]."+venNumF+")";
//                                    System.out.println(sql);
//                                    st1.execute(sql);

                                     sql="INSERT INTO "+tbl+" ("+DnkNumF+","+venCapaF+","+venNumF+","+venPLNumF+","+venQtyF+","+venPriceF+","+cuFtF+","+venderF+") " +
                                                "VALUES("+DnkNum+","+venCapa+","+venNum+","+venPLNum+","+venQty+","+venPrice+",'"+cuFt+"',"+vender+")";
//                                    System.out.println(sql);
                                        st1.execute(sql);



                                }

                                else if (vendor=="TX"){
                                    String DnkNum=rs.getString("DNK #");
                                    if (DnkNum==null){
                                        DnkNum="na";

                                    }
                                    if (DnkNum.length()==0){
                                        DnkNum="na";




                                    }


                                        DnkNum="'"+DnkNum+"'";


                                    String venNum=rs.getString("TYGP #");
                                    venNum="'"+venNum+"'";

                                    String venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    String venPLNum=rs.getString("partslink #");
                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";


                                    //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    String venPrice=rs.getString("dnk $");
                                    if (venPrice==null){
                                        venPrice="0";
                                    }
                                    if (venPrice.length()==0){
                                        venPrice="0";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPrice="'"+venPrice+"'";

                                    //                    fieldA4=    "TYG_TW_K";       //Package
//                                    String venQty=rs.getString("STD QTY");
//                                    venQty="'"+venQty+"'";

                                    //                    fieldA5=    "TYG_TW_C";         //Cu/FT
//                                    float cuFt=rs.getLong("CU/Ft");
                                    //                        cuFt=cuFt;

//                                    String vender=rs.getString("vender");
//                                    vender="'"+vender+"'";

                                    String sql="INSERT INTO "+tbl+" ([dnk #],capa,[tygp #],[partslink #],[dnk $]) " +
                                            "VALUES("+DnkNum+","+venCapa+","+venNum+","+venPLNum+","+venPrice+")";
                                    System.out.println(sql);
                                    st1.execute(sql);

                                }
                                else if (vendor=="GN"){
                                    String DnkNum=rs.getString("Customer Part #");

                                    if (DnkNum==null){
                                        DnkNum="na";
//                                        DnkNum="'"+DnkNum+"'";
                                    }
                                        if (DnkNum.length()<1){
                                        DnkNum="na";
//                                        DnkNum="'"+DnkNum+"'";

                                    }

                                    DnkNum="'"+DnkNum+"'";


                                    String venNum=rs.getString("item");
                                    venNum="'"+venNum+"'";

                                    String venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    String venPLNum=rs.getString("partsLink #");

                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";



                                    //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    String venPrice=rs.getString("net $");
                                    venPrice="'"+venPrice+"'";

                                    //                    fieldA4=    "TYG_TW_K";       //Package
                                    String venQty=rs.getString("STDpk");
                                    venQty="'"+venQty+"'";

                                    //                    fieldA5=    "TYG_TW_C";         //Cu/FT
//                                    float cuFt=rs.getLong("CU/Ft");
//                                    //                        cuFt=cuFt;
//
//                                    String vender=rs.getString("vender");
//                                    vender="'"+vender+"'";

                                    String sql="INSERT INTO "+tbl+" ([customer part #],capa,item,[partslink #],stdpk,[net $]) " +
                                            "VALUES("+DnkNum+","+venCapa+","+venNum+","+venPLNum+","+venQty+","+venPrice+")";
                                    System.out.println(sql);
                                    st1.execute(sql);

                                }
                                else if (vendor=="DP"){
//                                    String DnkNum=rs.getString("DNK#");
//                                    if (DnkNum.length()==0){
//                                        DnkNum="na";
//                                        DnkNum="'"+DnkNum+"'";
//
//                                    }else{
//                                        DnkNum="'"+DnkNum+"'";
//                                    }

                                    String venNum=rs.getString("DEPO NO");
                                    venNum="'"+venNum+"'";

                                    String venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    String venPLNum=rs.getString("partslink");
                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";



                                    //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    String venPrice=rs.getString("unit price");
                                    venPrice="'"+venPrice+"'";

                                    //                    fieldA4=    "TYG_TW_K";       //Package
                                    String venQty=rs.getString("qty ctn");
                                    venQty="'"+venQty+"'";
//
//                                    //                    fieldA5=    "TYG_TW_C";         //Cu/FT
//                                    float cuFt=rs.getLong("CU/Ft");
//                                    //                        cuFt=cuFt;
//
//                                    String vender=rs.getString("vender");
                                    vender="'"+vender+"'";

                                    String sql="INSERT INTO "+tbl+" (capa,[DEPO NO],partslink,[QTY CTN],[UNIT PRICE]) " +
                                            "VALUES("+venCapa+","+venNum+","+venPLNum+","+venQty+","+venPrice+")";
//                                    System.out.println(sql);
                                    st1.execute(sql);

                                }
                                else if (vendor=="AP"){
//                                    String DnkNum=rs.getString("DNK#");
//                                    if (DnkNum.length()==0){
//                                        DnkNum="na";
//                                        DnkNum="'"+DnkNum+"'";
//
//                                    }else{
//                                        DnkNum="'"+DnkNum+"'";
//                                    }

                                    String venNum=rs.getString("AP");
                                    venNum="'"+venNum+"'";

                                    String venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    String venPLNum=rs.getString("PRTLNK");
                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";


                                    //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    String venPrice=rs.getString("UPX");
                                    venPrice="'"+venPrice+"'";

                                    //                    fieldA4=    "TYG_TW_K";       //Package
                                    String venQty=rs.getString("STD P/K");
                                    venQty="'"+venQty+"'";

                                    //                    fieldA5=    "TYG_TW_C";         //Cu/FT
                                    float cuFt=rs.getLong("CUFTpER");
                                    //                        cuFt=cuFt;

//                                    String vender=rs.getString("vender");
//                                    vender="'"+vender+"'";

                                    String sql="INSERT INTO "+tbl+" (capa,AP,PRTLNK,[STD P/K],UPX,CUFTpER) " +
                                            "VALUES("+venCapa+","+venNum+","+venPLNum+","+venQty+","+venPrice+",'"+cuFt+"')";
//                                    System.out.println(sql);
                                    st1.execute(sql);

                                }
                                else if (vendor=="YCC"){
//                                    String DnkNum=rs.getString("DNK#");
//                                    if (DnkNum.length()==0){
//                                        DnkNum="na";
//                                        DnkNum="'"+DnkNum+"'";
//
//                                    }else{
//                                        DnkNum="'"+DnkNum+"'";
//                                    }

                                    String venNum=rs.getString("YCC");
                                    venNum="'"+venNum+"'";

                                    String venCapa=rs.getString("capa");
                                    venCapa="'"+venCapa+"'";

                                    String venPLNum=rs.getString("PARTLINK");
                                    if (venPLNum==null){
                                        venPLNum="na";
                                    }
                                    if (venPLNum.length()==0){
                                        venPLNum="na";
//                                        venPLNum="'"+venPLNum+"'";
                                    }
                                    venPLNum="'"+venPLNum+"'";


                                    //                    fieldA3=    "TYG_TW_P";      //PRICE
                                    String venPrice=rs.getString("PRICE");
                                    venPrice="'"+venPrice+"'";

                                    //                    fieldA4=    "TYG_TW_K";       //Package
                                    String venQty=rs.getString("PCS/CTN");
                                    venQty="'"+venQty+"'";

                                    //                    fieldA5=    "TYG_TW_C";         //Cu/FT
                                    float cuFt=rs.getLong("CUFt");
                                    //                        cuFt=cuFt;

//                                    String vender=rs.getString("vender");
//                                    vender="'"+vender+"'";

                                    String sql="INSERT INTO "+tbl+" (capa,YCC,partlink,[PCS/CTN],price,CUFT) " +
                                            "VALUES("+venCapa+","+venNum+","+venPLNum+","+venPrice+","+venQty+",'"+cuFt+"')";
                                    System.out.println(sql);
                                    st1.execute(sql);
                                }
                        }
//                    {
//                        DESCRIPT = rs.getString("DESCRIPT");
//                        DESCRIPT = DESCRIPT.replaceAll("'", " ");
//                        MODEL = rs.getString("MODEL");
//                        MODEL = MODEL.replaceAll("'", " ");
//                        NEW_DES = rs.getString("NEW_DES");
//                        NEW_DES = NEW_DES.replaceAll("'", " ");
//                    }

                }
            }


            catch(SQLException er)
            {
                er.printStackTrace();
            }



//            try
//            {
//                st3.execute("select * from tblnu;");
//                ResultSet rs1 = st3.getResultSet();
//                if(rs1 != null)
//                    while(rs1.next())
//                    {
//                        String CONTROL = rs1.getString("CONTROL").replaceAll("null", " ");
//                        String mmo = (new StringBuilder()).append(CONTROL).append(rs1.getString("REMARK")).toString();
//                        String mmo1 = mmo.trim();
//                        try
//                        {
//                            st2.execute("INSERT INTO tblinventory ( categoryid, [part#], description, unittype, unit, unitcost, sellingprice, instock, onorder, onhold, onrma, parvalue, location, serialized, [vendor#], discontinued, weight, taxable, vendor1id, vendor2id, vendor3id, lpp, lpf, ldp, lqp, [upc#], revenueglid, inventoryglid, currentcost, warehouseid, [product#], internet, internetprice, cogid, addinfulfillmentallowed, make, mdl, modeltype, beginyr, endyr, prefix, nagscode, dnkcode, cif, retailprice, sellingprice2, [memo], westwp, fob_t, ecp, ppgprice, slprice, mprice, shapeid, country, [bin#], prpkey, ppgloc, instock1, POSITION, NEW_DES ) " +
//                                    "SELECT top 1 b.CATALOG, b.item_no, b.descript, NULL, NULL, b.r_cost, b.retail, b.qoh, 0, 0, 0, 0, b.location, no, NULL, no, 0, yes, 0, 0, 0, 0, 0, 0, 0, NULL, 1, 1, 0, 3, b.part_no, yes, b.retail, 1, yes, b.brand, B.MODEL, B.NEW_MOD, b.yr_l, b.yr_h, NULL, NULL, b.item_no, b.cost, b.retail, b.retail, '" + mmo1 + "', 0, 0, " + "0, 0, 0, 0, 18, NULL, NULL, 0, NULL, " + "B.LI_WARE, POSITION, NEW_DES " +                                    "FROM TBLNU AS b where b.item_no ='" + rs1.getString("ITEM_NO") + "';");
//                        }
//                        catch(SQLException er) { }
//                    }
//            }
//            catch(SQLException er)
//            {
//                er.printStackTrace();
//            }
//            try
//            {
//                st5.execute("INSERT INTO tblmodel ( [part#], make, mdl, modeltype, Description, Beginyr, Endyr, WarehouseID, position, new_des ) SELECT item_no, brand, model, new_mod, descript, yr_l, yr_h, 3, position, new_des FROM tblnu;");
//            }
//            catch(SQLException er) { }
//            try
//            {
//                st6.execute("INSERT INTO TBLINVENTORYCOSTING ( INVID, QTY, DATERECEIVED, USED, COST, VENDORID ) SELECT DISTINCT A.INVID, A.INSTOCK, NOW(), 0, 0, NULL FROM TBLINVENTORY AS A INNER JOIN tblnu AS B ON A.[PART#]=B.[ITEM_NO];");
//            }
//            catch(SQLException er) { }
            st.close();
            st1.close();
            st2.close();
            st3.close();
            st4.close();
            st5.close();
            st6.close();
            con.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
            System.out.println(tbl+" "+totalfiles+" Completed!");
            totalfiles++;
    }
    }
//    public boolean checkDup(String partnum){
//        boolean found=false;
//
//
//        return found;
//    }

}
